<script setup>
import topNav from "../../components/topNav.vue";
import {
  onMounted,
  reactive,
  ref,
  getCurrentInstance,
  computed,
  nextTick,
} from "vue";
import { onLoad, onReachBottom, onShow } from "@dcloudio/uni-app";

import { appCategory } from "@/services/goods";
import { PlanProduct, PlanDetail } from "@/services/requiregoods.js";

//下拉触底
// onReachBottom(() => {
//   getappStockQuery();
// });

// import tabbarView from "../components/tabbar.vue";

const scrollTop = ref(0);
const upper = (e) => {
  console.log(e);
};
const lower = (e) => {
  console.log(e);
};
const scroll = (e) => {
  console.log(e);
  // scrollTop.value = e.detail.scrollTop;
};
const searchFun = () => {
  selectNumList.value.forEach((item, index) => {
    if (item.transferNum <= 0) {
      selectNumList.value.splice(index, 1);
    }
  });
  console.log("搜索");
  uni.setStorageSync("goodsSel", JSON.stringify(selectNumList.value));
  uni.navigateTo({
    url: "/pages/require_goods/goods_search/index?id=" + id.value,
  });
};

const ishowcamera = ref(false);
const scanFun = () => {
  selectNumList.value.forEach((item, index) => {
    if (item.transferNum <= 0) {
      selectNumList.value.splice(index, 1);
    }
  });
  console.log("扫码");
  uni.setStorageSync("goodsSel", JSON.stringify(selectNumList.value));
  // #ifdef H5
  uni.navigateTo({
    url: "/pages/code_sand/index?type=requiregoods" + "&id=" + id.value,
  });
  // #endif
  // 允许从相机和相册扫码
  // #ifdef APP-PLUS
  const systemInfo = uni.getSystemInfoSync();
  if (systemInfo.osName === "android") {
    if (uni.getStorageSync("isspermission")) {
    } else {
      ishowcamera.value = true;
    }

    plus.android.requestPermissions(["android.permission.CAMERA"], (e) => {
      if (e.deniedAlways.length > 0) {
        // 弹出提示框解释为何需要权限，引导用户打开设置页面开启

        ishowcamera.value = false;
      } else if (e.deniedPresent.length > 0) {
        //权限被临时拒绝
        // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
        ishowcamera.value = false;
      } else if (e.deniedAlways.length > 0) {
        //权限被永久拒绝
        // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
        ishowcamera.value = false;
      } else {
        plus.android.requestPermissions(
          ["android.permission.READ_EXTERNAL_STORAGE"],
          (e) => {
            if (e.deniedAlways.length > 0) {
              // 弹出提示框解释为何需要权限，引导用户打开设置页面开启

              ishowcamera.value = false;
            } else if (e.deniedPresent.length > 0) {
              //权限被临时拒绝
              // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限

              ishowcamera.value = false;
            } else if (e.deniedAlways.length > 0) {
              //权限被永久拒绝
              // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限

              ishowcamera.value = false;
            } else {
              ishowcamera.value = false;
              uni.setStorageSync("isspermission", true);

              uni.scanCode({
                scanType: ["barCode", "qrCode"],
                autoDecodeCharset: true,
                autoZoom: true,
                success: function (res) {
                  console.log("条码类型：" + res.scanType);
                  console.log("条码内容：" + res.result);

                  uni.navigateTo({
                    url:
                      "/pages/transfer/goods_search/index?code=" +
                      res.result +
                      "&id=" +
                      id.value,
                  });
                },
              });
            }
          }
        );
      }
    });
    return;
  }
  uni.scanCode({
    scanType: ["barCode", "qrCode"],
    autoDecodeCharset: true,
    autoZoom: true,
    success: function (res) {
      console.log("条码类型：" + res.scanType);
      console.log("条码内容：" + res.result);

      uni.navigateTo({
        url:
          "/pages/transfer/goods_search/index?code=" +
          res.result +
          "&id=" +
          id.value,
      });
    },
  });
  // #endif
};
// 使用计算属性来生成全名

const statusBarHeight = ref(0);
// #ifdef APP-PLUS
statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight;
// #endif

//选择改价
const itemObj = ref({});
const selectitem = ref(0);
const num = ref(0);
const selectLive = ref(1);
const tagObj = ref({ X: 0, Y: 0 });
const selectOne = ref(-1);
const selectTwo = ref(-1);
const selectThree = ref(0);
const toSelect = ref(false);

//键盘模块

const show = ref(false);
const showKeyboard = ref(true);
const priceValue = ref("30.10");
const keyboard = ref(null);
const keyboardHeight = ref(0);
const isSr = ref(false);
const themeVars = ref({
  numberKeyboardBackground: "#F7F8FA ",
  numberKeyboardKeyBackground: "#FFFFFF",
  numberKeyboardButtonBackground: "#FF5722",
});

const id = ref("");
const isDet = ref(false);

const clear = ref("");
onLoad((e) => {
  if (uni.getStorageSync("goodsSel")) {
    uni.removeStorageSync("goodsSel");
  }
  clear.value = e.clear ? e.clear : "";
  id.value = e.id ? e.id : "";
});
onMounted(() => {});
const screenHeight = ref(0);
onShow(() => {
  if (uni.getStorageSync("goodsSel")) {
    selectNumList.value = JSON.parse(uni.getStorageSync("goodsSel"));
  }
  if (newCategoryList.value.length > 0) {
    getappStockQuery(1);
  } else {
    getAppCategory();
  }
  uni.getSystemInfo({
    success: (res) => {
      const screenWidth = res.windowWidth; // 屏幕宽度，单位为px
      screenHeight.value = res.windowHeight; // 屏幕高度，单位为px
    },
  });
});

//商品分类
const categoryList = ref([]);
const newCategoryList = ref([]);
const getAppCategory = async () => {
  try {
    let res = await appCategory();
    categoryList.value = res.data;
    // form.value.categoryId = res.data[0].id;
    getappStockQuery(1);

    let arr = [];
    let newArr = [];
    let newArr2 = [];

    res.data.forEach((item, index) => {
      if (!item.parentId) {
        arr.push({ ...item, select: false, children: [] });
      } else {
        newArr.push({ ...item });
      }
    });
    arr.forEach((item, index) => {
      newArr.forEach((item2, index2) => {
        if (item.id == item2.parentId) {
          // item2.children = item.children || [];

          item.children.push({ ...item2, select: false, children: [] });
          newArr.splice(index2, 1);
        }
      });
    });
    arr.forEach((item, index) => {
      item.children.forEach((element, index) => {
        newArr.forEach((item2, index2) => {
          if (element.id == item2.parentId) {
            element.children.push({ ...item2, select: false });
          }
        });
      });
    });
    newCategoryList.value = arr;
  } catch (e) {}
};

const clickItem = (item, index, num, e) => {
  console.log(e);
  if (toSelect.value) {
    return;
  }
  toSelect.value = true;
  if (index != 2) {
    newCategoryList.value.forEach((item3, index3) => {
      item3.children.forEach((item2, index2) => {
        item2.select = false;
      });
    });
  }
  selectLive.value = index;
  if (index == 1) {
    selectName.value = item.name;
    if (!item.id) {
      selectOne.value = 0;
      // if (
      //   newCategoryList.value[selectOne.value - 1].children[selectTwo.value]
      // ) {
      //   newCategoryList.value[selectOne.value - 1].children[
      //     selectTwo.value
      //   ].select = false;
      // }
    } else {
      selectOne.value = num;
    }
  }
  if (index == 2) {
    selectNameTwo.value = item.name;
    let isshows = true;
    newCategoryList.value.forEach((item3, index3) => {
      item3.children.forEach((item2, index2) => {
        if (item2.id != item.id) {
          item2.select = false;
          isshows = false;
        }
      });
    });
    // if (isshows) {
    //   item.select = !item.select;
    // }
    item.select = !item.select;

    selectTwo.value = num;
  }
  if (index == 3) {
    console.log("item", selectOne.value, selectTwo.value);
    selectNameThree.value = item.name;
    item.select = false;
    selectThree.value = num;
  }
  if (e) {
    tagObj.value = {
      X: e.detail.x,
      Y: e.detail.y,
    };
  }

  console.log("tagObj.value", tagObj.value);

  toSelect.value = false;
  if (form.value.categoryId == item.id) {
    return;
  }
  form.value.categoryId = item.id;
  getappStockQuery(1);
};
const lowerto = (e) => {
  getappStockQuery();
};

//获取商品
const form = ref({
  categoryId: "",
  pageIndex: 1,
  pageSize: 20,
  barCode: "",
  code: "",
  name: "",
  skuCode: "",
  categoryId: "",
  available: "",
});
console.log(form.value);
const productData = ref([]);
const loading = ref(true);

const getappStockQuery = async (index) => {
  if (index == 1) {
    productData.value = [];
  }
  if (index) {
    form.value.pageIndex = index;
  }
  loading.value = true;
  try {
    let res = await PlanProduct(form.value);
    if (res.code == 200) {
      if (selectNumList.value.length > 0) {
        res.data.forEach((item) => {
          let isyou = true;

          selectNumList.value.forEach((element) => {
            console.log("element", element.id == item.id);
            if (element.id == item.id) {
              item.transferNum = element.transferNum;

              isyou = false;
            }
          });
          if (isyou) {
            item.transferNum = 0;
          }
        });
      } else {
        // res.data = [];
        if (res.data) {
          res.data.forEach((item) => {
            item.transferNum = 0;
          });
        } else {
          res.data = [];
        }
      }

      productData.value = productData.value.concat(res.data);

      console.log(productData.value);
      form.value.pageIndex = form.value.pageIndex + 1;
      loading.value = false;
    } else {
    }

    console.log(res);

    if (id.value && !isDet.value && !clear.value) {
      let res = await PlanDetail({
        id: id.value,
      });
      if (res.code == 200) {
        isDet.value = true;
        res.data.details.forEach((item) => {
          let isyou = false;
          productData.value.forEach((element) => {
            if (item.productId == element.id) {
              isyou = true;
              element.transferNum = item.orderNum;
              selectNumList.value.push(element);
              goodsNum.value = goodsNum.value + item.orderNum;
            }
          });
          if (!isyou) {
            selectNumList.value.push({
              id: item.productId,
              transferNum: item.orderNum,
              image: item.productImage,
              barCode: item.productCode,
              code: "",
              name: item.productName,
              skuCode: "",
              categoryName: item.categoryName,
              brandName: "",
              unit: item.productUnit,
              dhCode: "",
              offerPrice: item.taxPrice ? item.taxPrice : "",
            });
            goodsNum.value = goodsNum.value + item.orderNum;

            // {
            // "id": "1933435661714579456",
            // "barCode": "",
            // "code": "GD20250613160557905",
            // "name": "浦秀兰",
            // "skuCode": "98",
            // "categoryName": "",
            // "brandName": "无",
            // "unit": "id",
            // "available": true,
            // "image": "https://loremflickr.com/400/400?lock=4834535961608205",
            // "dhCode": 298,
            // "dhPlu": 298,
            // "supplierId": "1906663274334785536",
            // "supplierName": "测试2",
            // "offerPrice": 5
            // }
          }
        });
        // productData.value = res.data;
        loading.value = false;
      }
    }
  } catch (e) {
    console.log(e);
  }
};

//提交改价

const onBlue = async () => {
  try {
    let res = await salePriceCreate({
      productId: itemObj.value.id,
      revisePrice: priceValue.value,
      description: "手机端操作",
    });
    if (res.code == 200) {
      showToast("修改成功");
      num.value = num.value + 1;
      productData.value[selectitem.value].newsalePrice = priceValue.value;
      // productData.value[selectitem.value].salePrice=priceValue.value

      // getappStockQuery(1);
      show.value = false;
    } else {
      showToast(res.msg);
    }
  } catch (e) {
    showToast(e.msg);
  }
};
const onInput = (item) => {
  setTimeout(() => {
    priceValue.value = handlePriceInput(priceValue.value);
  }, 100);

  console.log(item);
};

const handlePriceInput = (event) => {
  let value = event;

  // 过滤掉非数字和小数点的字符
  value = value.replace(/[^0-9.]/g, "");

  // 确保只有一个小数点
  const parts = value.split(".");
  if (parts.length > 2) {
    value = parts[0] + "." + parts.slice(1).join("");
  }

  // 如果以小数点开头，添加 '0'
  if (value.startsWith(".")) {
    value = "0" + value;
  }

  // 如果小数点后超过两位，截断
  const decimalParts = value.split(".");
  if (decimalParts.length === 2 && decimalParts[1].length > 2) {
    value = decimalParts[0] + "." + decimalParts[1].slice(0, 2);
  }
  console.log("value", value);
  // form.value.price = value;
  return value;
};

//改价列表
const goRecord = () => {
  if (selectNumList.value.length <= 0) {
    uni.showToast({
      title: "请先选择商品",
      icon: "none",
    });
    return;
  }

  selectNumList.value.forEach((item, index) => {
    if (item.transferNum <= 0) {
      selectNumList.value.splice(index, 1);
    }
  });

  uni.setStorageSync("goodsSel", JSON.stringify(selectNumList.value));

  uni.navigateTo({
    url: "/pages/require_goods/goods_swith/index?id=" + id.value,
  });
};
//商品分类
const selectName = ref("全部商品");
const selectNameTwo = ref("");
const selectNameThree = ref("");
const oneSelectIndex = ref("");
const themeVarsCollapse = reactive({
  collapseItemContentFontSize: "24rpx",
  cellFontSize: "24rpx",
  // cellVerticalPadding: "0rpx",
  cellHorizontalPadding: "10rpx",
  collapseItemContentPadding: "0rpx",
  collapseItemContentBackground: "#ededed",
});
const activeName = ref("1");
const onCollapseChange = (name) => {
  console.log("SDASASD", name);
  setTimeout(() => {
    activeName.value = name;
  }, 100);
};
const open = (e) => {
  console.log("open", e);
};

// 定义 close 方法
const close = (e) => {
  console.log("close", e);
};
const cell = ref(false);
// 定义 change 方法
const change = (e) => {
  let newId = form.value.categoryId;
  toSelect.value = true;

  selectLive.value = 1;

  newCategoryList.value.forEach((item, index) => {
    item.children.forEach((item2, index2) => {
      item2.select = false;
    });
  });
  let isSelect = false;

  e.forEach((item, index) => {
    if (item.status == "open") {
      isSelect = true;
      // #ifdef APP-PLUS

      selectOne.value = index;
      // #endif
      // #ifdef H5

      selectOne.value = index - 1;
      // #endif
      if (item.name == 0) {
        selectOne.value = index - 1;
        form.value.categoryId = "";
        selectName.value = "全部商品";
      } else {
        form.value.categoryId = newCategoryList.value[item.name - 1]
          ? newCategoryList.value[item.name - 1].id
          : "";
        selectName.value = newCategoryList.value[item.name - 1]
          ? newCategoryList.value[item.name - 1].name
          : "";
      }
    }
  });
  if (isSelect) {
    cell.value = true;
  } else {
    selectOne.value = -1;
    cell.value = false;
  }
  toSelect.value = false;
  if (newId == form.value.categoryId) {
    return;
  }
  selectTwo.value = -1;
  getappStockQuery(1);
};

const closeshow = () => {
  newCategoryList.value.forEach((item, index) => {
    item.children.forEach((item2, index2) => {
      item2.select = false;
    });
  });
};

const keyWord = ref(null);

//金额键盘
const inp = (e) => {
  console.log("e", e);
};

const hide = () => {
  if (num.value > 0) {
    // numblur();
  } else {
    jsnum.value = 0;
  }
  isinputto.value = false;
  isshowput.value = true;
};
const confirm = async () => {
  // getcomputeBrokerage(Number(num.value));
  try {
    let res = await salePriceCreate({
      productId: itemObj.value.id,
      revisePrice: priceValue.value,
      description: "手机端操作",
    });
    if (res.code == 200) {
      showToast("修改成功");
      num.value = num.value + 1;
      productData.value[selectitem.value].newsalePrice = priceValue.value;
      // productData.value[selectitem.value].salePrice=priceValue.value
      nextTick(() => {
        keyWord.value.close();
        // isshowput.value = true;
      });

      // getappStockQuery(1);
      show.value = false;
    } else {
      showToast(res.msg);
    }
  } catch (e) {
    showToast(e.msg);
  }
};
const numblur = () => {
  // getcomputeBrokerage(Number(num.value));
};
const closePay = () => {
  keyWord.value.close();
};
const goodsNum = ref(0);
// const value = ref(0);
const selectNumList = ref([]);
const selectItem = ref({});
const showMode = ref(false);
const showIndex = ref(0);
const showTwoIndex = ref(0);

const onClickMinus = (item, index) => {
  // if (item.stockNum <= 0) {
  //   uni.showToast({
  //     title: "库存不足",
  //     icon: "none",
  //   });
  //   return;
  // }
  selectItem.value = item;
  showIndex.value = index;

  showTwoIndex.value = selectNumList.value.length;
  item.transferNum = item.transferNum + 1;
  if (item.transferNum > item.stockNum) {
    showMode.value = true;
  }

  if (selectNumList.value <= 0) {
    selectNumList.value.push(item);
    getNum();
    return;
  }
  let isnew = true;
  selectNumList.value.forEach((item1, index1) => {
    if (item1.id == item.id) {
      isnew = false;
      selectNumList.value[index1] = item;
    }
  });
  if (isnew) {
    selectNumList.value.push(item);
  }
  getNum();

  // selectNumList.value = [...selectNumList.value, ...[item]];
};
const goodsNumTo = ref(0);
function getNum() {
  let num = 0;
  let goodsNums = 0;
  selectNumList.value.forEach((item) => {
    num += item.transferNum;
    if (item.transferNum && item.transferNum > 0) {
      goodsNums = goodsNums + 1;
    }
  });
  goodsNumTo.value = goodsNums;
  goodsNum.value = num;
}

const valChange = (item, index, e) => {
  selectItem.value = item;
  showIndex.value = index;

  // if (e.value > item.stockNum) {
  //   showMode.value = true;
  // }
  // if (!e.value) {
  //   selectNumList.value.splice(index, 1);
  // }

  if (selectNumList.value <= 0) {
    selectNumList.value.push(item);
    getNum();
    return;
  }
  let isnew = true;
  selectNumList.value.forEach((item1, index1) => {
    if (item1.id == item.id) {
      showTwoIndex.value = index1;
      selectNumList.value[index1] = item;
      isnew = false;
    }
  });
  if (isnew) {
    showTwoIndex.value = selectNumList.value.length;
    selectNumList.value.push(item);
  }
  console.log(selectNumList.value, "sadas");
  setTimeout(() => {
    getNum();
  }, 10);
};

const blurChange = (item, index, e) => {
  if (e.value == "") {
    item.transferNum = 0;
  }
};

const cancelFun = () => {
  showMode.value = false;
  newCategoryList.value[showIndex.value].transferNum =
    newCategoryList.value[showIndex.value].stockNum;
  if (selectNumList.value[showTwoIndex.value]) {
    selectNumList.value[showTwoIndex.value].transferNum = selectNumList.value[
      showTwoIndex.value
    ].stockNum
      ? selectNumList.value[showTwoIndex.value].stockNum
      : 0;
  }

  getNum();
};
const confirmFun = () => {
  showMode.value = false;
};

//商品选择
const showSelect = ref(false);

const closeSelect = () => {
  showSelect.value = false;
  selectNumList.value.forEach((item, index) => {
    if (item.transferNum <= 0) {
      selectNumList.value.splice(index, 1);
    }
  });
};

const onClickItem = (item, index) => {
  selectItem.value = item;
  showIndex.value = index;

  showTwoIndex.value = selectNumList.value.length;
  item.transferNum = item.transferNum;
  if (item.transferNum > item.stockNum) {
    showMode.value = true;
  }

  if (selectNumList.value <= 0) {
    selectNumList.value.push(item);
    getNum();
    showSelect.value = true;
    return;
  }
  let isnew = true;
  selectNumList.value.forEach((item1, index1) => {
    if (item1.id == item.id) {
      isnew = false;
      selectNumList.value[index1] = item;
    }
  });
  if (isnew) {
    selectNumList.value.push(item);
  }
  getNum();
  showSelect.value = true;
};
</script>

<template>
  <view @click="closeshow">
    <jia-PayKeyboard
      :confirmStyle="{ backgroundColor: '#1679FB' }"
      class="keyWord-index"
      :overlayClose="true"
      ref="keyWord"
      v-model="priceValue"
      @input="inp"
      @confirm="confirm"
      @hide="hide"
    >
      <view class="PayKeyboard-k">
        <view class="icon-top">
          <up-icon
            @click="closePay"
            name="close"
            color="#86909C"
            size="20"
          ></up-icon
        ></view>
        <view class="PayKeyboard-k-title">{{ itemObj.name }}</view>
        <view class="PayKeyboard-k-des">{{ itemObj.barCode }}</view>
        <view class="link-to"></view>
        <view class="PayKeyboard-k-num">
          <view class="PayKeyboard-k-num-title">新售价</view>
          <view class="PayKeyboard-k-num-input">
            <up-form labelPosition="left" ref="form1" labelWidth="0">
              <up-form-item label=" " borderBottom ref="item1">
                <up-input
                  v-model="priceValue"
                  disabled
                  disabledColor="#ffffff"
                  border="none"
                  class="input"
                  fontSize="72rpx"
                  color="#ff5722"
                ></up-input>
                <template #right>
                  <text>元</text>
                </template>
              </up-form-item>
            </up-form>
          </view>
        </view>
      </view>
    </jia-PayKeyboard>

    <topNav
      title="要货选择商品"
      @search="searchFun"
      @scan="scanFun"
      rType="icon"
      :clickable="false"
    ></topNav>
    <view
      class="goods_form"
      :style="'height: calc(100vh - ' + (statusBarHeight + 'px') + ' - 88rpx)'"
    >
      <view class="goods_left">
        <scroll-view
          :style="
            'height: calc(100vh - ' + (statusBarHeight + 'px') + ' - 88rpx)'
          "
          :scroll-top="scrollTop"
          scroll-y="true"
          class="scroll-Y"
          @scrolltoupper="upper"
          @scrolltolower="lower"
          @scroll="scroll"
        >
          <up-collapse
            :accordion="true"
            @change="change"
            @close="close"
            @open="open"
          >
            <up-collapse-item :name="0" @click.stop="clickItem(item, 1, index)">
              <template #title>
                <view
                  :class="
                    -1 == selectOne ? 'u-page__item__title__slot-title' : ''
                  "
                  >{{ "全部商品" }}</view
                >
              </template>
            </up-collapse-item>
            <!-- :title="item.name"
            :name="item.id" -->
            <up-collapse-item
              v-for="(item, index) in newCategoryList"
              :key="index"
              :name="index + 1"
              @click.stop="clickItem(item, 1, index)"
            >
              <template #title>
                <view
                  :class="
                    selectOne == index ? 'u-page__item__title__slot-title' : ''
                  "
                  >{{ item.name }}</view
                >
              </template>
              <view
                class="list-itemTwo"
                :class="
                  selectOne == index && selectTwo == indexTwo
                    ? 'sel-list-itemTwo'
                    : ''
                "
                v-for="(itemTwo, indexTwo) in item.children"
                :key="indexTwo"
                @click.stop="clickItem(itemTwo, 2, indexTwo, $event, $el)"
              >
                {{ itemTwo.name }}

                <view
                  @click.stop
                  v-if="itemTwo.select"
                  class="list-itemThree"
                  :style="
                    newCategoryList.length - index > 5
                      ? 'left: calc( 150rpx );top: ' + (tagObj.Y - 15) + 'px; '
                      : 'left:calc(150rpx ) ;bottom: calc( ' +
                        screenHeight +
                        'px' +
                        ' - ' +
                        (tagObj.Y + 15) +
                        'px ); '
                  "
                >
                  <view
                    class="item_arrow"
                    :style="
                      newCategoryList.length - index > 5
                        ? 'top: ' + 15 + 'px; '
                        : 'bottom: calc( ' + 15 + 'px ); '
                    "
                  ></view>
                  <view
                    @click.stop="clickItem(itemThree, 3, indexThree)"
                    v-for="(itemThree, indexThree) in itemTwo.children"
                    :key="indexThree"
                    >{{ itemThree.name }}</view
                  >
                </view>
              </view>
            </up-collapse-item>
          </up-collapse>

          <view style="height: 100px; width: 100%"></view>
        </scroll-view>
      </view>

      <view class="goods_right">
        <scroll-view
          :style="
            'height: calc(100vh - ' + (statusBarHeight + 'px') + ' - 88rpx)'
          "
          :scroll-top="scrollTop"
          scroll-y="true"
          class="scroll-R"
          @scrolltoupper="upper"
          @scrolltolower="lowerto"
          @scroll="scroll"
        >
          <view class="select-titles">
            {{ selectLive >= 1 ? selectName : "" }}
            {{ selectLive >= 2 ? "/" + selectNameTwo : ""
            }}{{ selectLive >= 3 ? "/" + selectNameThree : "" }}</view
          >
          <view
            class="scroll-Y-item"
            @click="onClickItem(item, index)"
            v-for="(item, index) in productData"
            :key="index"
          >
            <view class="scroll-item-left">
              <image
                :src="
                  item.image
                    ? item.image
                    : 'https://cloud-erp.yibaitao.cn/0d2f4178-7754-4686-9213-b174f745258b.png'
                "
                mode="scaleToFill"
              />
            </view>
            <view class="scroll-item-right">
              <view class="goods-item-title">
                <text
                  class="title-tag"
                  :class="item.salesType == 2 ? 'title-tag2' : ''"
                  >{{ item.salesType == 2 ? "寄售" : "自销" }}</text
                >
                <text>{{ item.name }}</text></view
              >

              <view class="goods-item-spec" v-if="!item.dhCode">
                商品码:{{
                  item.barCode && item.barCode ? item.barCode : "--"
                }}</view
              >
              <view class="goods-item-spec" v-if="item.dhCode">
                称码:{{ item.dhCode ? item.dhCode : "" }}</view
              >

              <view class="goods-item-price">
                <text>
                  {{ item.offerPrice ? "¥" + item.offerPrice : "暂无报价" }}
                  {{ item.unit && item.offerPrice ? "/" + item.unit : "" }}
                  <text class="goods-item-spec">库存:</text>
                  {{ item.stockNum || 0 }}</text
                >
              </view>
            </view>
            <view class="goods-item-num">
              <view @click.stop="onClickMinus(item, index)">
                <up-icon
                  name="plus-circle-fill"
                  color="#1679fb"
                  size="60rpx"
                  v-if="item.transferNum <= 0"
                ></up-icon>
              </view>
              <!-- :max="item.stockNum" -->
              <up-number-box
                @click.stop
                v-if="item.transferNum > 0"
                buttonWidth="50rpx"
                buttonSize="50rpx"
                bgColor="#ffffff"
                v-model="item.transferNum"
                @blur="(e) => blurChange(item, index, e)"
                @change="(e) => valChange(item, index, e)"
                min="0"
              ></up-number-box>
              <view v-if="item.transferNum > item.stockNum" class="selectindex"
                >超出当前库存</view
              >
            </view>
          </view>

          <view class="noData" v-if="productData.length <= 0 && !loading">
            <view class="noData-img">
              <image src="@/static/nodate/datas.png" mode="scaleToFill" />
              <view>暂无商品</view>
            </view>
          </view>

          <view
            style="height: 100px; width: 100%"
            v-if="productData.length > 0"
          ></view>
        </scroll-view>
      </view>
    </view>

    <view class="goods_bt">
      <view class="goods_bt_to">
        <text
          >共<text class="blue">{{ selectNumList.length }}</text
          >款,<text class="blue">{{ goodsNum }}</text
          >件</text
        >
        <van-button class="val-button" type="primary" @click="goRecord"
          >确认</van-button
        >
      </view>
    </view>
  </view>
  <!-- cancelText="取消" :showCancelButton="true" -->
  <!-- (selectItem.stockNum - selectItem.transferNum) -->
  <up-modal
    :show="showMode"
    :title="selectItem.name + ', 库存超出,当前库存为' + selectItem.stockNum"
    width="500rpx"
    :content="''"
    @cancel="cancelFun"
    @confirm="cancelFun"
    confirmText="取消"
  ></up-modal>

  <view class="show-camera" v-if="ishowcamera">
    <view class="show-camera-k">
      <view class="show-sm"> 设备权限使用说明 </view>
      <view class="show-des">
        为了给您带来更好的服务，需要获取您的相机权限与读取图片及文件权限，用于更换上传图片、扫一扫等功能，对于您授权的信息我们竭尽全力提供安全保护。
      </view>
    </view>
  </view>

  <up-popup
    :show="showSelect"
    :closeable="true"
    mode="bottom"
    round="10"
    @close="closeSelect"
  >
    <view class="popups">
      <view class="goods_p">
        <view class="goods">
          <view class="left">
            <image :src="selectItem.image" mode="scaleToFill" />
          </view>
          <view class="right">
            <view class="title">{{ selectItem.name }}</view>

            <view class="code" v-if="!selectItem.dhCode">
              商品码:{{
                selectItem.barCodeList && selectItem.barCodeList[0]
                  ? selectItem.barCodeList[0]
                  : selectItem.barCode
              }}</view
            >
            <view class="code" v-if="selectItem.dhCode">
              称码:{{ selectItem.dhCode ? selectItem.dhCode : "" }}</view
            >

            <view class="code">
              规格:{{ selectItem.spec ? selectItem.spec : "--" }}</view
            >

            <view class="price"
              >¥{{ selectItem.offerPrice }}/{{ selectItem.unit }}</view
            >
          </view>
        </view>
        <view class="num">
          <view class="left"> 数量 </view>
          <view class="right">
            <view class="num-box">
              <up-number-box
                min="0"
                v-model="selectItem.transferNum"
                @blur="(e) => blurChange(selectItem, 1, e)"
                @change="(e) => valChange(selectItem, 1, e)"
              ></up-number-box>
            </view>
          </view>
        </view>
      </view>
      <view class="goods_bt">
        <view class="goods_bt_to">
          <text
            >共<text class="blue">{{ goodsNumTo }}</text
            >款,<text class="blue">{{ goodsNum }}</text
            >件</text
          >
          <van-button class="val-button" type="primary" @click="goRecord"
            >确认</van-button
          >
        </view>
      </view>
    </view>
  </up-popup>
</template>

<style lang="scss" scoped>
@import "./index.scss";
</style>
